package ar.edu.itba.jMEBowling;

import ar.edu.itba.jMEBowling.scenario.Scenario;

import com.jme.input.KeyInput;
import com.jme.input.action.InputActionEvent;

public class ActionPerformer {

	private Scenario scenario;
	private ShotSpecification shotSpecification;

	public ActionPerformer(Scenario scenario,
			ShotSpecification shotSpecification) {
		this.scenario = scenario;
		this.shotSpecification = shotSpecification;
	}

	public GameStatus performAction(GameStatus gameStatus,
			InputActionEvent evt, Runner game) {
		if (gameStatus == GameStatus.INMENU) {
			if (KeyInput.get().isKeyDown(KeyInput.KEY_UP)) {
				game.getGameMenu().keyUp();
			}

			if (KeyInput.get().isKeyDown(KeyInput.KEY_DOWN)) {
				game.getGameMenu().keyDown();
			}

			if (KeyInput.get().isKeyDown(KeyInput.KEY_LEFT)) {
				game.getGameMenu().keyLeft(shotSpecification);
			}

			if (KeyInput.get().isKeyDown(KeyInput.KEY_RIGHT)) {
				game.getGameMenu().keyRight(shotSpecification);
			}
			if (KeyInput.get().isKeyDown(KeyInput.KEY_RETURN)) {
				return game.getGameMenu().keyEnter();
			}
		} else if (gameStatus == GameStatus.INHELP) {
			if (KeyInput.get().isKeyDown(KeyInput.KEY_Q)) {
				return game.getGameMenu().keyQ();
			}
		} else {
			if (KeyInput.get().isKeyDown(KeyInput.KEY_M)) {
				game.setBeforePause(gameStatus);
				game.pause();
				game.setInPause(true);
				game.setMenuCamera();
				game.getGameMenu().showAllOptions();
				gameStatus = GameStatus.INMENU;

			}
			if (KeyInput.get().isKeyDown(KeyInput.KEY_SPACE)) {
				if (gameStatus == GameStatus.WAITINGXPOS) {
					return GameStatus.WAITINGXANGLE;
				} else if (gameStatus == GameStatus.WAITINGXANGLE) {
					return GameStatus.WAITINGARMANGLE;
				} else if (gameStatus == GameStatus.WAITINGARMANGLE) {
					return GameStatus.WAITINGPOW;
				} else if (gameStatus == GameStatus.WAITINGPOW) {
					return GameStatus.THROWBALL;
				}
			}
		}
		return gameStatus;
	}
}
